package com.elock.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.elock.base.core.Page;
import com.elock.base.core.Pageable;
import com.elock.base.core.dao.impl.DaoCenter;
import com.elock.base.core.util.ConvertUtil;

/**
 * Dao - 锁实时状态
 * @author 仁德
 */
@Repository("elockRealtimeStatusDao")
public class ElockRealtimeStatusDao extends DaoCenter {

	public Page<Map<String, Object>> findPage(String ids, String carIds,
			Pageable pageable) {

		String sql = "select er.*,e.car_number,e.position,e.berth from elock_realtime_status er left join elock_car e on er.elock_id=e.elock_id where er.elock_id in ("
				+ ids
				+ ")";
		if (!ConvertUtil.isEmpty(carIds)) {
			sql += " and e.car_id in (" + carIds + ")";
		}
		Page<Map<String, Object>> page = getNativeDao().findPageMap(sql, null, pageable);

		return page;
	}

	public List<Map<String, Object>> findList(String ids, String carIds, Date elockDate) {

		String sql = "select er.*,e.car_number,e.position,e.berth from elock_realtime_status er left join elock_car e on er.elock_id=e.elock_id where er.elock_id in ("
				+ ids
				+ ")";
		if (!ConvertUtil.isEmpty(carIds)) {
			sql += " and e.car_id in (" + carIds + ")";
		}
		Object[] objs = null;
		if (elockDate != null) {
			sql += " and er.modify_date > ?";
			objs = new Object[] { elockDate };
		}
		sql += " order by er.modify_date desc";
		List<Map<String, Object>> list = getNativeDao().findListMap(sql, objs, 0);
		return list;
	}

}